/*
 * @Author: jiu yin
 * @Date: 2023-03-30 11:56:32
 * @LastEditTime: 2023-05-22 14:14:13
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \init-admin\vite.config.js
 * jiu
 */
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus'
import visualizer from 'rollup-plugin-visualizer';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    //setup 设置name
    vueSetupExtend(),
    //按需引入el
    AutoImport({
      resolvers: [
        ElementPlusResolver(),
        // 自动导入图标组件
        IconsResolver({ prefix: 'Icon', }),],
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: ['vue'],
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        // 自动注册图标组件
        IconsResolver({ enabledCollections: ['ep'] }),

      ],
    }),

    Icons({
      autoInstall: true,
    }),

  ],
  server: {
    open: true,
    port: 8082,
    host: '192.168.0.147',
    hmr: true,
    proxy: {
      // '/api': {
      //   target: 'http://192.168.0.135',
      //   changeOrigin: true,
      // }
    },

  },

  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',//消除i18n警告
    },
    //extensions数组的意思是在import组件的时候自动补全.vue等文件后缀
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  },

  build: {
    minify: 'terser',
    terserOptions: {
      compress: {
        //生产环境时移除console
        drop_console: true,
        drop_debugger: true,
      },
    },

    rollupOptions: {
      plugins: [
        visualizer({
          open: true, //依赖包可视化
        }),
      ],
    },

  },

})
